/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-02-03
 * Time: 15:18
 *
 * https://www.nowcoder.com/share/jump/7745334641706944690267
 */
public class BM68 {

    public int minPathSum(int[][] matrix) {
        int m = matrix.length, n = matrix[0].length;
        for (int i = 1; i < n; i++) {
            matrix[0][i] += matrix[0][i - 1];
        }
        for (int j = 1; j < m; j++) {
            matrix[j][0] += matrix[j - 1][0];
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                matrix[i][j] += Math.min(matrix[i - 1][j], matrix[i][j - 1]);
            }
        }
        return matrix[m - 1][n - 1];
    }
}
